import { Component, ChangeDetectorRef } from '@angular/core';
import { CommonService } from '../service/common.service';
import { StorageService } from '../service/storage.service';
import { EventService } from '../service/event.service';
import { Router } from '@angular/router';

@Component({
  selector: 'app-tabs',
  templateUrl: 'tabs.page.html',
  styleUrls: ['tabs.page.scss']
})

export class TabsPage {

  constructor(private router: Router,private changeDetectorRef: ChangeDetectorRef,
    private common: CommonService,private storage: StorageService,private eventService: EventService) {}

  tabname: any= 'tab1';
  tabchange(e){
    this.tabname = e.tab;
    this.changeDetectorRef.detectChanges();
    // console.log(e)
    // if(this.tabname == 'tab4'){
    //   this.getInfo()
    // }
  }

  // 传入id获取用户基本信息
  getInfo(){
    // 获取登录信息
    const api = '/tbr/getUserInfo';
    const params = {userId: this.storage.get('PersonalInfo').userId};
    this.common.post(api,params,false).then((response: any)=>{
      // console.log(response)
      if(response.code == 200){
        // 保存信息
        this.storage.set('PersonalInfo',response.data);
        this.eventService.event.emit('useraction');
      }else if(response.msg='登录超时或已在其他设备登录，请重新登录！'){
        // alert(response.msg)
        this.router.navigateByUrl('login');
      }else{
        alert(response.msg);
      }
    });
  }

}
